package lanou.autohome.forum;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

import java.util.ArrayList;

import lanou.autohome.R;
import lanou.autohome.SouSuoActivity;
import lanou.autohome.forum.fragments.ForumCommonFragment;
import lanou.autohome.forum.fragments.ForumFeaturedFragment;
import lanou.autohome.forum.fragments.ForumHotFragment;

/**
 * Created by dllo on 16/8/15.
 */
public class ForumFragment extends Fragment {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private ForumAdapter forumAdapter;
    ArrayList<Fragment>fragments;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_forum,null);

        tabLayout = (TabLayout) view.findViewById(R.id.forum_tablayout);
        viewPager = (ViewPager) view.findViewById(R.id.forum_viewpager);

        fragments = new ArrayList<>();
        forumAdapter =  new ForumAdapter(getChildFragmentManager());
        ImageButton imageButton = (ImageButton) view.findViewById(R.id.btn_sousuo);

        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.btn_sousuo:
                        Intent intent = new Intent(getContext(), SouSuoActivity.class);
                        startActivity(intent);
                }
            }
        });

        fragments.add(new ForumFeaturedFragment());
        fragments.add(new ForumHotFragment());
        fragments.add(new ForumCommonFragment());

        forumAdapter.setFragments(fragments);
        viewPager.setAdapter(forumAdapter);
        tabLayout.setupWithViewPager(viewPager);

        return view;
    }


}
